home *** CD-ROM | disk | FTP | other *** search
/ Meeting Pearls 2 / Meeting Pearls Vol. II (1995)(GTI - Schatztruhe)[!].iso / Pearls / comm / Envoy / Talk / tk_svc.asm < prev    next >
Assembly Source File  |  1994-04-17  |  9KB  |  342 lines

  1. ;---------------------------------------------------------------------------
  2. ;Talk Service written by Jeffrey A. Litz
  3. ;
  4. ;litz@cs.uwp.edu  -or-  Jeff_Litz@EDTNG.Kenosha.WI.US
  5. ;
  6. ;Copyright ©1994 JL Productions.
  7. ;---------------------------------------------------------------------------
  8.  
  9.         OPTIMON
  10.  
  11. ;---------------------------------------------------------------------------
  12.  
  13.         NOLIST
  14.         
  15.         INCDIR "include:"
  16.  
  17.         INCLUDE "exec/types.i"
  18.         INCLUDE "exec/libraries.i"
  19.         INCLUDE "exec/lists.i"
  20.         INCLUDE "exec/alerts.i"
  21.         INCLUDE "exec/initializers.i"
  22.         INCLUDE "exec/resident.i"
  23.         INCLUDE "libraries/dos.i"
  24.  
  25.         INCLUDE "tk_rev.i"
  26.         INCLUDE "tkbase.i"
  27.  
  28.         LIST
  29.  
  30. ;---------------------------------------------------------------------------
  31.  
  32.         XREF    _StartService
  33.         XREF    _Server
  34.         XREF    _GetServiceAttrsA
  35.         XREF    ENDCODE
  36.  
  37. ;---------------------------------------------------------------------------
  38.  
  39.         XDEF    LibInit
  40.         XDEF    LibOpen
  41.         XDEF    LibClose
  42.         XDEF    LibExpunge
  43.         XDEF    LibReserved
  44.         XDEF    _TALKPassword
  45.         XDEF    _TALKSignalMask
  46.         XDEF    _TALKUser
  47.         XDEF    _TALKEntityName
  48.         XDEF    _TALKSMProc
  49.         XDEF    _TALKServer
  50.         XDEF    _TALKError
  51.  
  52.         XDEF    __sprintf
  53.         
  54.         XDEF    _SysBase
  55.  
  56. ;---------------------------------------------------------------------------
  57.  
  58. ; First executable location, must return an error to the caller
  59. Start:
  60.         moveq   #-1,d0
  61.         rts
  62.  
  63. ;-----------------------------------------------------------------------
  64.  
  65. ROMTAG:
  66.         DC.W    RTC_MATCHWORD           ; UWORD RT_MATCHWORD
  67.         DC.L    ROMTAG                  ; APTR  RT_MATCHTAG
  68.         DC.L    ENDCODE                 ; APTR  RT_ENDSKIP
  69.         DC.B    RTF_AUTOINIT            ; UBYTE RT_FLAGS
  70.         DC.B    VERSION                 ; UBYTE RT_VERSION
  71.         DC.B    NT_LIBRARY              ; UBYTE RT_TYPE
  72.         DC.B    0                       ; BYTE  RT_PRI
  73.         DC.L    LibName                 ; APTR  RT_NAME
  74.         DC.L    LibId                   ; APTR  RT_IDSTRING
  75.         DC.L    LibInitTable            ; APTR  RT_INIT
  76.  
  77. LibName DC.B 'talk.service',0
  78. LibId   VERSTAG
  79.  
  80.         CNOP    0,4
  81.  
  82. LibInitTable:
  83.         DC.L    TALKSvc_SIZEOF
  84.         DC.L    LibFuncTable
  85.         DC.L    LibDataTable
  86.         DC.L    LibInit
  87.  
  88. V_DEF   MACRO
  89.         DC.L    \1
  90.         ENDM
  91.  
  92. LibFuncTable:
  93.         V_DEF   LibOpen
  94.         V_DEF   LibClose
  95.         V_DEF   LibExpunge
  96.         V_DEF   LibReserved
  97.  
  98.         V_DEF   _RexxReserved
  99.         V_DEF   _StartService
  100.         V_DEF   _GetServiceAttrsA
  101.  
  102.         DC.L   -1
  103.  
  104. LibDataTable:
  105.         INITBYTE   LN_TYPE,NT_LIBRARY
  106.         INITLONG   LN_NAME,LibName
  107.         INITBYTE   LIB_FLAGS,(LIBF_SUMUSED!LIBF_CHANGED)
  108.         INITWORD   LIB_VERSION,VERSION
  109.         INITWORD   LIB_REVISION,REVISION
  110.         INITLONG   LIB_IDSTRING,LibId
  111.         DC.W       0
  112.  
  113.         CNOP    0,4
  114.  
  115. ;-----------------------------------------------------------------------
  116.  
  117. ; Library Init entry point called when library is first loaded in memory
  118. ; On entry, D0 points to library base, A0 has lib seglist, A6 has SysBase
  119. ; Returns 0 for failure or the library base for success.
  120. LibInit:
  121.         movem.l a0/a5/a6/d7,-(sp)
  122.         move.l  d0,a5
  123.         move.l  d0,_TALKBase
  124.         move.l  a6,TALK_SysBase(a5)
  125.         move.l  a6,_SysBase(pc)
  126.         move.l  a0,TALK_SegList(a5)
  127.  
  128.         move.l  #AO_DOSLib,d7
  129.         lea     DOSName(pc),a1
  130.         bsr.s   OpenLib
  131.         move.l  d0,TALK_DOSBase(a5)
  132.  
  133.         move.l  #AO_UtilityLib,d7
  134.         lea     UtilityName(pc),a1
  135.         bsr.s   OpenLib
  136.         move.l  d0,TALK_UtilityBase(a5)
  137.  
  138.         lea     TALK_OpenLock(a5),a0
  139.         CALL    InitSemaphore
  140.  
  141.         clr.l   TALK_Entity(a5)
  142.         clr.l   TALK_NIPCBase(a5)
  143.  
  144.         move.l  a5,d0
  145.  
  146.         movem.l (sp)+,a0/a5/a6/d7
  147.         rts
  148.  
  149. OpenLib:
  150.         moveq   #LIBVERSION,d0
  151.         CALL    OpenLibrary
  152.         move.l  (sp)+,a0        ; pop return address
  153.         tst.l   d0              ; did lib open?
  154.         beq.s   FailInit        ; nope, so exit
  155.         jmp     (a0)            ; yes, so return
  156.  
  157. FailInit:
  158.         bsr     CloseLibs
  159.         or.l    #AG_OpenLib,d7
  160.         CALL    Alert
  161.         movem.l (sp)+,a0/a5/a6/d7
  162.         moveq   #0,d0
  163.         rts
  164.  
  165. LIBVERSION    EQU  37
  166.  
  167. DOSName         DC.B "dos.library",0
  168. UtilityName     DC.B "utility.library",0
  169. NIPCName        DC.B "nipc.library",0
  170.  
  171.         CNOP    0,4
  172.  
  173. ;-----------------------------------------------------------------------
  174.  
  175. ; Library open entry point called every OpenLibrary()
  176. ; On entry, A6 has ServicesBase, task switching is disabled
  177. ; Returns 0 for failure, or ServicesBase for success.
  178. LibOpen:
  179.         ; see if nipc.library is already open
  180.         tst.l   TALK_NIPCBase(a6)
  181.         bne.s   2$
  182.  
  183.         ; lock anyone else out for a while, since we need to Wait()
  184.         lea.l   TALK_OpenLock(a6),a0
  185.         move.l  a6,-(sp)
  186.         move.l  TALK_SysBase(a6),a6
  187.         CALL    ObtainSemaphore
  188.  
  189.         ; open nipc.library
  190.         lea.l   NIPCName,a1
  191.         clr.l   d0
  192.         CALL    OpenLibrary
  193.         move.l  (sp),a6
  194.         move.l  d0,TALK_NIPCBase(a6)
  195.  
  196.         ; unlock the rest of the word.
  197.         lea.l   TALK_OpenLock(a6),a0
  198.         move.l  TALK_SysBase(a6),a6
  199.         CALL    ReleaseSemaphore
  200.         move.l  (sp)+,a6
  201.  
  202.         ; did nipc open?
  203.         tst.l   TALK_NIPCBase(a6)
  204.         bne.s   2$
  205.         clr.l   d0  ; too bad...
  206.         rts
  207.  
  208.         ; open okay...
  209. 2$      addq.w  #1,LIB_OPENCNT(a6)
  210.         bclr    #LIBB_DELEXP,LIB_FLAGS(a6)
  211.         move.l  a6,d0
  212.         rts
  213.  
  214. ;-----------------------------------------------------------------------
  215.  
  216. ; Library close entry point called every CloseLibrary()
  217. ; On entry, A6 has ServicesBase, task switching is disabled
  218. ; Returns 0 normally, or the library seglist when lib should be expunged
  219. ; due to delayed expunge bit being set
  220. LibClose:
  221.         subq.w  #1,LIB_OPENCNT(a6)
  222.  
  223.         ; if delayed expunge bit set, then try to get rid of the library
  224.         btst    #LIBB_DELEXP,LIB_FLAGS(a6)
  225.         bne.s   CloseExpunge
  226.  
  227.         ; delayed expunge not set, so stick around
  228.         moveq   #0,d0
  229.         rts
  230.  
  231. CloseExpunge:
  232.         ; if no library users, then just remove the library
  233.         tst.w   LIB_OPENCNT(a6)
  234.         beq.s   DoExpunge
  235.  
  236.         ; still some library users, so just flush unused resources
  237.         bclr    #LIBB_DELEXP,LIB_FLAGS(a6)
  238.         moveq   #0,d0
  239.         rts
  240.  
  241. ;-----------------------------------------------------------------------
  242.  
  243. ; Library expunge entry point called whenever system memory is lacking
  244. ; On entry, A6 has ServicesBase, task switching is disabled
  245. ; Returns the library seglist if the library open count is 0, returns 0
  246. ; otherwise and sets the delayed expunge bit.
  247. LibExpunge:
  248.         tst.w   LIB_OPENCNT(a6)
  249.         beq.s   DoExpunge
  250.  
  251.         bset    #LIBB_DELEXP,LIB_FLAGS(a6)
  252.         moveq   #0,d0
  253.         rts
  254.  
  255. DoExpunge:
  256.         movem.l d2/a5/a6,-(sp)
  257.         move.l  a6,a5
  258.         move.l  TALK_SegList(a5),d2
  259.  
  260.         move.l  a5,a1
  261.         REMOVE
  262.  
  263.         move.l  TALK_SysBase(a5),a6
  264.         bsr.s   CloseLibs
  265.  
  266.         move.l  a5,a1
  267.         moveq   #0,d0
  268.         move.w  LIB_NEGSIZE(a5),d0
  269.         sub.l   d0,a1
  270.         add.w   LIB_POSSIZE(a5),d0
  271.         CALL    FreeMem
  272.  
  273.         move.l  d2,d0
  274.         movem.l (sp)+,d2/a5/a6
  275.         rts
  276.  
  277. ;-----------------------------------------------------------------------
  278.  
  279. LibReserved:
  280.         moveq   #0,d0
  281.         rts
  282.  
  283. CloseLibs:
  284.         move.l  TALK_DOSBase(a5),a1
  285.         CALL    CloseLibrary
  286.  
  287.         move.l  TALK_NIPCBase(a5),a1
  288.         CALL    CloseLibrary
  289.  
  290.         move.l  TALK_UtilityBase(a5),a1
  291.         GO      CloseLibrary
  292.  
  293. ;-----------------------------------------------------------------------
  294.  
  295. ; TALKServer Entry Point
  296.  
  297. _TALKServer:
  298.         movea.l _TALKBase(pc),a6
  299.         movea.l _TALKUser(pc),a0
  300.         movea.l _TALKPassword(pc),a1
  301.         movea.l _TALKEntityName(pc),a2
  302.  
  303.         jmp     _Server
  304.  
  305. _TALKBase       DC.L  0
  306. _TALKUser       DC.L  0
  307. _TALKPassword   DC.L  0
  308. _TALKEntityName DC.L  0
  309. _TALKSignalMask DC.L  0
  310. _TALKSMProc     DC.L  0
  311. _TALKError      DC.L  0
  312. _SysBase       DC.L  0  ; KLUDGE! HACK! HACK! HACK! for amiga.lib linking
  313.  
  314. ;-----------------------------------------------------------------------
  315.  
  316. ; Reserved Function for ARexx.
  317.  
  318. _RexxReserved:
  319.         moveq.l #0,d0
  320.         rts
  321.  
  322. ;-----------------------------------------------------------------------
  323. __sprintf:
  324.         movem.l a2/a3/a4/a6,-(sp)
  325.         move.l  5*4(sp),a3
  326.  
  327.         move.l  6*4(sp),a0
  328.         lea     7*4(sp),a1
  329.         lea     stuffChar(pc),a2
  330.         move.l  TALK_SysBase(a6),a6
  331.         CALL    RawDoFmt
  332.         movem.l (sp)+,a2/a3/a4/a6
  333.         rts
  334.  
  335. stuffChar:
  336.         move.b  d0,(a3)+
  337.         rts
  338.  
  339. ;-----------------------------------------------------------------------
  340.  
  341.         END
  342.